package sms;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;
import com.sun.jersey.core.util.MultivaluedMapImpl;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.core.MediaType;


/**
 * Created by cwp on 2017/2/14.
 */
public class SmsUtil {


    /* public static String send2(String phone,String content) throws Exception{
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost  = new HttpPost("http://sms-api.luosimao.com/v1/send.json");

        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("mobile", phone));


        UrlEncodedFormEntity urlEncodedFormEntity=new UrlEncodedFormEntity(params,"utf-8");
        httpPost.setEntity(urlEncodedFormEntity);


        return null;
    }*/

   public static String send(String phone,String content) {
        Client client = Client.create();
        client.addFilter(new HTTPBasicAuthFilter(
                "api","key-0d1ebf30ec2e49e8afd39cb2b98d34f0"));
        WebResource webResource = client.resource(
                "https://api.ucpaas.com");
        MultivaluedMapImpl formData = new MultivaluedMapImpl();
        formData.add("mobile", phone);
        formData.add("message", content);
        ClientResponse response =  webResource.type(MediaType.APPLICATION_FORM_URLENCODED ).
                post(ClientResponse.class, formData);
        String textEntity = response.getEntity(String.class);
        int status = response.getStatus();
        //System.out.print(textEntity);
        //System.out.print(status);
        return textEntity;
    }
}